<?php

class ClientsController extends AppController {
    var $name = 'Clients';

    /*
     * Muestra un listado de todos los clientes
     */
    function admin_index() {
        // recupero los datos de todos los clientes
        // i fetch clients data
        $clients = $this->paginate('Client');
        $this->set('clients', $clients);
    }

    function admin_clients() {
        $this->admin_index();
    }

    function admin_add() {
        if (!empty($this->data)) {
            if ($this->Client->save($this->data)) {
                $message = __('I18N_SUCCESSFULY_ADDED');
            }
            else {
                $message = __('I18N_ERROR_NOT_ADDED');
            }
            $this->showMessage($message);
        }
    }

    function admin_delete($id) {
        $this->Client->delete($id);
        $message = __('I18N_SUCCESSFULY_REMOVED');
        $this->showMessage($message);
    }

    function admin_edit($id) {
        $this->Client->id = $id;
        if (empty($this->data)) {
            $this->data = $this->Client->read();
        } else {
            if ($this->Client->save($this->data)) {
                $message = __('I18N_SUCCESSFULY_UPDATED');
            }
             else {
                $message = __('I18N_ERROR_NOT_UPDATED');
            }
            $this->showMessage($message);
        }
    }

    function admin_view($id) {
        if (!$id) {
            $message = sprintf(__('I18N_INVALID_ENTITY'),__('I18N_CLIENT'));
            $this->showMessage($message);
        }
        $this->Client->id = $id;
        $clientData = $this->Client->read();
        $this->set('client',$clientData);
    }
}

?>
